package com.lifeng.mynetty.server.http;

import com.lifeng.mynetty.handler.HttpServerHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;

/**
 *
 */
public class HttpServerInitializer extends ChannelInitializer<SocketChannel> {
    //字符编码
    private String charset;
    //内容类型
    private String contentType;
    //
    private String uri;

    public HttpServerInitializer() {

    }

    public HttpServerInitializer(String charset,String contentType,String uri){
        this.charset = charset;
        this.contentType = contentType;
        this.uri = uri;
    }

    @Override
    public void initChannel(SocketChannel ch) {
        ChannelPipeline p = ch.pipeline();
        p.addLast(new HttpRequestDecoder());
        p.addLast(new HttpResponseEncoder());
        HttpServerHandler httpServerHandler = new HttpServerHandler();
        httpServerHandler.setCharset(charset);
        httpServerHandler.setContentType(contentType);
        httpServerHandler.setUri(uri);
        p.addLast(httpServerHandler);
    }
}
